package com.itboye.textillexepres.db;

import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteDatabase.CursorFactory;
import android.database.sqlite.SQLiteOpenHelper;

public class SearchDBHelper extends SQLiteOpenHelper {
	public static final String SEARCHDB_NAME = "search.db";
	public static final String SEARCHDB_TABLENAME = "search";
	public static final String SEARCHDB_TABLENUMBER = "2";
	public static final int VERSION = 1;

	public SearchDBHelper(Context context, String name, CursorFactory factory,
			int version) {
		super(context, name, factory, version);
		// TODO Auto-generated constructor stub
	}

	public SearchDBHelper(Context context) {
		// TODO Auto-generated constructor stub
		super(context, SEARCHDB_NAME, null, VERSION);
	}

	@Override
	public void onCreate(SQLiteDatabase db) {
		// TODO Auto-generated method stub
		StringBuffer sBuffer = new StringBuffer();
		sBuffer.append("CREATE TABLE [" + SEARCHDB_TABLENAME + "] (");
		sBuffer.append("[_id] Integer primary key ,");
		sBuffer.append("[prop_name] TEXT,");
		sBuffer.append("[prop_id] TEXT UNIQUE,");
		sBuffer.append("[type] TEXT)");

		// 执行创建表的SQL语句
		db.execSQL(sBuffer.toString());
	}

	@Override
	public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
		// TODO Auto-generated method stub
		db.execSQL("DROP TABLE IF EXISTS " + SEARCHDB_TABLENAME);
		onCreate(db);
	}

}
